<template>
  <div class="content">
    <div class="header">
      <div class="left">
        <div>
          <b>订单提交成功！请尽快完成付款，未支付订单 <span class="actice-class">7s </span>后将自动取消。
          </b>
          <span class="xs_remain">剩余 {{ remain }} </span>
        </div>
        <div class="order-water">支付流水：<span class="actice-class">88888888888888888</span> </div>

      </div>
      <div class="right">

        <b>支付金额：<span class="price">￥457</span></b>

      </div>
    </div>
    <div class="payway">
      <div class="title">请选择支付方式</div>
      <div class="wechat">
        <span class="pay_out" @click="changePayFn(1)">
          <i :class=" activeIndex==1? 'radio_sty-on':'radio_sty'" />
          <label><span class="pay_icon wx_type">微信支付</span></label>
        </span>
      </div>
      <div class="paypal">
        <span class="pay_out" @click="changePayFn(2)">
          <i :class=" activeIndex==2? 'radio_sty-on':'radio_sty'" />
          <label for="paypal"><span class="pay_icon zfb_type">支付宝支付</span></label>
        </span>
      </div>
    </div>
    <div class="pay_button">
      <button class="submitPay" type="button" @click="goPayFn">立即支付</button>
    </div>
    <el-dialog
      title="微信/支付宝扫码支付"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <div class="qrcode-box">
        <img :src="qrcode" alt="">
      </div>
    </el-dialog>

  </div>
</template>
<script>
import QRCode from 'qrcode'
export default {
  name: 'OrderPay',
  components: {},
  data() {
    return {
      activeIndex: 1,
      qrcode: '',
      dialogVisible: false,
      timerObj: null,
      timer: null,
      remain: '', // 倒计时
      remainNew: ''

    }
  },
  watch: {

  },
  mounted() {
    this.timerFn()
  },
  beforeDestroy() {
    clearInterval(this.timerObj)
  },
  methods: {
    // 选择支付方式
    changePayFn(code) {
      if (code == 1) {
        this.activeIndex = 1
      } else {
        this.activeIndex = 2
      }
    },
    // 立即支付
    async goPayFn() {
      // 跳转支付成功页的逻辑暂时写在这里
      this.$router.push({
        path: './paySuccess'
      })
      this.dialogVisible = true
      const res = {
        'code': '0',
        'msg': '处理成功',
        'data': {
          'channelPayNo': '1013202402070000010009467253',
          'payWayCode': 1007,
          'paySerialnoId': 13520644240207,
          'prePayTn': null,
          'cashierUrl': null,
          'qrcodeUrl': 'https://qr.yeepay.com/oc/3pHSdCnA',
          'orderCode': null
        },
        'sub_code': null,
        'success': true
      }

      const url = await QRCode.toDataURL(res.data.qrcodeUrl)
      this.qrcode = url
      // 轮询实时查询支付状态
      this.timerObj = setInterval(function() {
        // 接口查询支付状态
        console.log(2222222222)
      }, 1000)
    },
    /* 倒计时*/

    timerFn() {
      const systemTime = '2024-02-08 09:58:17'
      const end = Number(1707718478117)
      const startT = new Date(systemTime.replace(/-/g, '/'))
      let intDiff = (end - startT) / 1000
      const vm = this
      this.timer = setInterval(function() {
        let day = 0
        let hour = 0
        let minute = 0
        let second = 0 // 时间默认值
        if (intDiff > 0) {
          day = Math.floor(intDiff / (60 * 60 * 24))
          hour = Math.floor(intDiff / (60 * 60)) - (day * 24)
          minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60)
          second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60)
        } else {
          clearInterval(this.timer)

          return false
        }
        if (day <= 9) day = '0' + day
        if (hour <= 9) hour = '0' + hour
        if (minute <= 9) minute = '0' + minute
        if (second <= 9) second = '0' + second
        if (day == '00') {
          vm.remain = hour + '时' + minute + '分' + second + '秒'
        } else {
          vm.remain = day + '天' + hour + '时' + minute + '分' + second + '秒'
        }
        intDiff--
      }, 1000)
    }

  }
}
</script>
<style scoped lang="scss">
.content {
  width: 1200px;
  margin: 0 auto;
  background: #fff;
  .actice-class{
    color: #FF8000;
  }
  .header{
    padding: 10px;
    display: flex;
    justify-content: space-between;
    .left{
    font-size: 16px;
    color: #666;
    .order-water{
      margin: 7px 0;
      font-size: 14px;
      color: #333;
      line-height: 24px;
    }
    .xs_remain{
      font-size: 14px;
      color: #FF1B1B;
      margin-left: 50px;
    }

  }
  .right{

    .price {
    color: #FF8000;
    font-size: 25px;
    }
  }
  }

  .payway{
    width: 1188px;
    border: 1px solid #d3d3d3;
    overflow: hidden;
    padding: 15px 15px 0 15px;
    margin: 0 auto;
    .title {
    font-size: 16px;
    font-weight: bold;
    padding-bottom: 10px;
    padding-top: 20px;
    }
    div {
    width: 1130px;
    margin: 0 auto;
    border-bottom: 1px solid #d3d3d3;
    padding: 15px 0;
    line-height: 30px;
    span{
      font-size: 16px;
      color: #666;
    }
    }
    .paypal{
      border-bottom: none !important;
    }
   label {
    display: inline-block;
    height: 30px;
    line-height: 30px;
    margin-left: 40px;
}
    .pay_out {
    position: relative;
    display: flex;
    .radio_sty {
    position: absolute;
    display: block;
    width: 14px;
    height: 14px;
    background: url(.../../../../../assets/image/rd_off.png) no-repeat center;
    top: 7px;
}
    .radio_sty-on {
        position: absolute;
        display: block;
        width: 14px;
        height: 14px;
        background: url(.../../../../../assets/image/rd_on.png) no-repeat center;
        top: 7px;
    }
    .wx_type {
    background: url(.../../../../../assets/image/wechat.png) no-repeat left center;
    background-size: 30px;
    }
    .zfb_type{
      background: url(.../../../../../assets/image/paypal.png) no-repeat left center;
      background-size: 30px;
    }
    .pay_icon {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        padding-left: 45px;
    }

}

  }
  .pay_button{
    padding: 20px;
    text-align: right;
    .submitPay{
      background: #e54346;
      color: #fff;
      padding: 8px 20px;
      border: none;
      font-size: 16px;
    }

  }
  .qrcode-box{

    text-align: center;
    img{
      width: 300px;
      height: 300px;
    }
  }
}
>>>.el-dialog__header {
    text-align: center;
}
</style>
